package com.zgm.ch05.aop.pointcutAdvisor.controlFlow._4_1_10;

import org.springframework.aop.Advisor;
import org.springframework.aop.Pointcut;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.ControlFlowPointcut;
import org.springframework.aop.support.DefaultPointcutAdvisor;

public class ControlFlowDemo {

	public static void main(String[] args) {
		new ControlFlowDemo().run();
	}
	
	private void run() {
		TestBean target = new TestBean();
		
		Pointcut pc = new ControlFlowPointcut(ControlFlowDemo.class, "test");
		Advisor advisor = new DefaultPointcutAdvisor(pc, new SimpleBeforeAdvice());
		
		ProxyFactory pf = new ProxyFactory();
		pf.setTarget(target);
		pf.addAdvisor(advisor);
		
		TestBean proxy = (TestBean) pf.getProxy();
		
		System.out.println("普通调用：");
		proxy.foo();
		
		System.out.println("控制流调用：");
		this.test(proxy);
		
	}
	
	private void test(TestBean bean) {
		bean.foo();
	}
	
}
